<?php
/**
 * Created by PhpStorm.
 * User: wsgt
 * Date: 2021/04/14
 * Time: 15:34
 */
namespace app\common\library;
use think\Log as TPLog;
class WsgtLog{
    protected static $instance = null;
    protected $isSingleFile = true;

    private function __construct(){
        TPLog::setSingleFile();
    }

    public static function instance(){
        if(!self::$instance instanceof self) {
            self::$instance = new self();
        }
        return self::$instance;
    }

    public function multiFile(){
        $this->isSingleFile = false;
        TPLog::setMultiFile();
    }

    public function setFilename($filename){
        TPLog::setFilename($filename);
    }

    public function info($msg, $title = ''){
        is_numeric($msg) && $msg = strval($msg);
        is_bool($msg) && $msg = bool2str($msg);
        if($title) {
            $title = '[ ' . $title . ' ] ' . PHP_EOL;
            is_string($msg) && $msg = $title . $msg;
            is_array($msg) && $msg = $title . var_export($msg,true);
        }
        TPLog::info($msg);
    }

    public function save(){
        TPLog::save();
    }

    public function error($msg, $title = ''){
        if($title) {
            $title = '[ ' . $title . ' ] ' . PHP_EOL;
            is_string($msg) && $msg = $title . $msg;
            is_array($msg) && $msg = $title . var_export($msg,true);
        }
        TPLog::error($msg);
    }

    public function clear(){
        TPLog::clear();
    }
}